<template>
  <div class="building">
    <ParkList @change="handleChangePark" />
    <div class="building-right">
      <Tabs
        @change="handleChangeTab"
        :currentKey="currentComponentKey"
        :tabsConfig="tabsConfig"
      />
      <div class="building-right-bottom">
        <KeepAlive>
          <component
            :parkId="parkId"
            ref="currentComponentRef"
            :is="currentComponent"
          ></component>
        </KeepAlive>
      </div>
    </div>
  </div>
</template>
<script setup>
import { onMounted, ref, shallowRef } from 'vue'
import ParkList from '@/components/parkList/index.vue'
import Tabs from '@/components/tabs/index.vue'
import BuildingList from './components/buildingList.vue'
import MapList from './components/mapList.vue'

const componentConfig = {
  buildingList: BuildingList,
  mapList: MapList,
}
const tabsConfig = ref([
  {
    name: '列表展示',
    value: 'buildingList',
    hasSearch: true,
  },
  {
    name: '地图展示',
    value: 'mapList',
    hasSearch: true,
  },
])
const currentComponentRef = ref()
const currentComponentKey = ref('')
const currentComponent = shallowRef(null)
const handleChangeTab = (val) => {
  currentComponentKey.value = val
  currentComponent.value = componentConfig[currentComponentKey.value]
}
const parkId = ref('')
const handleChangePark = (val) => {
  parkId.value = val
}
const currentType = ref('')
onMounted(() => {
  handleChangeTab('buildingList')
})
</script>
<style lang="scss" scoped>
.building {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  &-right {
    flex: 1;
    height: 100%;
    &-bottom {
      width: 100%;
      height: calc(100% - 50px);
      overflow-y: hidden;
    }
  }
}
</style>
